package controllers;

import play.*;
import play.mvc.*;
import play.data.*;
import java.util.*;
import javax.persistence.Query;
import models.*;
import play.db.jpa.JPA;


/**
 * Manage Depts related operations.
 */

public class Depts extends Controller {
  
    public static void index() {
        render();
    }

    /**
     * Get depts json.
     */
    public static void json(int page, int pagesize) {
    	
    	List<Dept> depts = Dept.all().fetch(page, pagesize);      	 
    	long total = Dept.count();
    	
    	HashMap<String,Object> obj = new HashMap<String,Object>();
    	obj.put("Rows", depts);
    	obj.put("Total", total);
    	
    	renderJSON(obj);
    }

    /**
     * Add a dept.
     */
    public static void add(Dept dept) {        
        
    }
    /**
     * Get depts json.
     */
    public static void findAll() {
        List<Dept> depts = Dept.findAll();
        renderJSON(depts);

    }
     static User connectedUser() {
        String userId = session.get("logged");
        return (userId==null) ? null : (User)User.findById(Long.parseLong(userId));
    }

    /**
     * Update a dept.
     */
    public static void save(Dept dept) {       
        dept.save();
        ok();
//        index();
    }
    
    /**
     * Delete a dept.
     */
    public static void delete(long id) {
        Dept.findById(id)._delete();
        ok();
    }
  
}

